The present invention relates to the field of computer systems; more particularly, the present invention relates to executing load instructions before it is known that they can be legally executed (i.e., speculatively).
Some computers have the capability to execute instructions out of order. In other words, the central processing unit (CPU) and the computer system is capable of executing one instruction before a previous instruction in the instruction execution stream. To execute computer programs more quickly in a computer system, it is often helpful to move instructions earlier in the execution stream than the programmer had initially planned. In particular, it is useful to move instructions to a location prior to branch instructions, the execution of which determine whether the moved instructions would have been executed. Such instructions are called speculative instructions because they are executed prior to knowing that the instructions are going to be executed (since the branch instruction has not been executed yet). However, memory operations typically must be executed in order to maintain memory consistency, especially when their execution would create incorrect results.
Exceptions may arise as a result of program execution. Although it is desirable to execute instructions speculatively, it is important not to take exceptions on such instructions where an instruction potentially may not actually be executed. As discussed above, whether these speculative instructions will actually be executed is based on whether a branch (or other conditional statement) is actually taken or not. Thus, when instructions are speculative, one cannot take an exception because the path that caused the exception might not have ever occurred.
One prior art solution to execute programs more quickly is to move only those instructions that are proven not to cause exceptions. This does work well for most integer instructions as they, in general, do not cause exceptions. Loads and divides can cause exceptions. A load instruction allows a central processing unit that processes data in a computer system to receive the data from memory. A load instruction typically specifies an address to a location in memory at which the desired data is stored. The load instruction also usually specifies the amount of data that is desired. Using the address and the amount of data specified, the memory may be accessed and the desired data obtained. It is very difficult to prove ahead of time that a load will not cause exception.
One solution to allow a program to execute more quickly is to move a load instruction earlier in the execution stream and replace them with loads which do not take exceptions. These are called dismissible loads. This is an effective solution. However, the program may no longer raise an exception which would have been raised had the change in program order not been made.
Another solution may be to use an additional bit in each register result indicating whether an instruction would have caused an exception. This allows for general speculation and still maintains the knowledge that an exception occurred. If using a register that has the bit set to indicate an exception occurred, the register is merely passed along with its results. A disadvantage of this approach is that it requires an additional register state which must be saved and restored.
The present invention allows load instructions to be moved earlier in the instruction stream for speculative execution while still allowing exceptions to occur when they should.
A method and apparatus for speculatively executing a load is described. The present invention includes a method and apparatus for executing a dismissible load instruction as part of, and earlier in, a series of executable instructions than the load. The present invention also includes a method and apparatus for executing another instruction, as part of the series of executable instructions, to determine whether to take an exception for the dismissible load instruction.